package com.itboye.jinpuyiyuan.wxapi;


import android.app.Activity;

import android.content.Intent;
import android.os.Bundle;

import android.util.Log;

import com.itboye.jinpuyiyuan.activity.pay.PayActivity;
import com.itboye.jinpuyiyuan.utils.sputil.Const;
import com.itboye.jinpuyiyuan.widget.loadingutil.MAlert;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;



/**
 * Created by Administrator on 2018/9/20 0020.
 */

public class WXPayEntryActivity extends Activity implements  com.tencent.mm.opensdk.openapi.IWXAPIEventHandler {
    private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";

    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.pay_result);

        api = WXAPIFactory.createWXAPI(this, Const.APP_ID_WX);
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }


    @Override
    public void onReq(com.tencent.mm.opensdk.modelbase.BaseReq baseReq) {

    }

    @Override
    public void onResp(com.tencent.mm.opensdk.modelbase.BaseResp baseResp) {
        Log.d("resp==",baseResp.toString());
        if (baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            int code = baseResp.errCode;
            switch (code) {
                case 0:
//                    ToastUtil.show("支付成功");
                    MAlert.alert("支付成功");

                    finish();
                break;
                case -1:
                    MAlert.alert("支付失败");
                    finish();
                break;
                case -2:
                    MAlert.alert("支付取消");
                    finish();
                break;
                default:
                    MAlert.alert("支付失败");
                    finish();
                    break;
            }



        }
    }
//    @Override
//    public void onReq(BaseReq baseReq) {
//
//    }

//    @Override
//    public void onResp(BaseResp baseResp) {
//        Log.d("wxpay==",baseResp.toString());
//        if (baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
//
//            int code = baseResp.errCode;
//            switch (code) {
//                case 0:
////                    ToastUtil.show("支付成功");
//                    MAlert.alert("支付成功");
//                break;
//                case -1:
//                    MAlert.alert("支付失败");
//                break;
//                case -2:
//                    MAlert.alert("支付取消");
//                break;
//                default:
//                    MAlert.alert("支付失败");
////                    setResult(RESULT_OK);
////                    finish();
//                    break;
//            }
//
//
//
//        }
//    }
}
